package com.xian.im.modules.command.system.handler;

import com.xian.feign.GroupChannelClient;
import com.xian.im.common.constant.CommandCodeConstant;
import com.xian.im.common.constant.CommandConstant;
import com.xian.im.common.proto.MsgRequest;
import com.xian.im.common.proto.MsgResponse;
import com.xian.im.common.utils.sys.SpringContextHolder;
import com.xian.im.modules.command.system.SystemCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

/**
 * @program: xian-im-server
 * @description:
 * @author: liru.xian
 * @create: 2021-02-01 09:06
 **/
@Slf4j
public class SystemGroupHandler implements SystemCommand {
    /**
     *
     *
     * @param request
     */
    @Override
    public void exec(MsgRequest request) {
        String groupId = request.getGroupUniqueId();
        MsgResponse response = MsgResponse.buildSuccess();
        BeanUtils.copyProperties(request, response);
        response.setCmd(CommandConstant.SYSTEM_CMD);
        response.setCmdCode(CommandCodeConstant.SYSTEM_GROUP);
        response.setBody(request.getBody());
        GroupChannelClient channelClient = SpringContextHolder.getBean(GroupChannelClient.class);
        //发送消息
        channelClient.pushGroupSystemMessage( groupId,response);
    }
    /**
     * code
     *
     * @return
     */
    @Override
    public String cmdCode() {
        return CommandCodeConstant.SYSTEM_GROUP;
    }
}
